<?php
	@session_start();
	
	//--
	include "includes/configuration.php";
	include "lib/xtpl/xtemplate.class.php";
	
	//-- Set current theme
	$current_theme = 'default';
	define ( 'TEMP_PATH', ROOT_PATH . 'templates/' . $current_theme . '/' );
	
	//--
	$xtpl_main = new XTemplate ( TEMP_PATH . "layout.html" );
	$xtpl_main->assign ( "base_url", BASE_URL );
	$xtpl_main->assign ( "temp_url", BASE_URL . 'templates/' . $current_theme . '/' );
	
	//--
	$mod = ( isset ( $_GET ['mod'] ) ) ? $_GET ['mod'] : 'home';
	$act = ( isset ( $_GET ['act'] ) ) ? $_GET ['act'] : 'main';
	
	$filename = ROOT_PATH . "modules/" . $mod . "/" . $act . ".php";
	
	if ( file_exists ( $filename ) ) {
		$xtpl = new XTemplate ( ROOT_PATH . "modules/" . $mod . "/" . $act . ".html" );
		include $filename;
	} else {
		include ROOT_PATH . "modules/home/error.php";
		$xtpl = new XTemplate ( ROOT_PATH . "modules/home/error.html" );
	}
	
	$xtpl->assign ( "temp_url", BASE_URL . 'templates/' . $current_theme . '/' );
	
	//-- Check member status
	if(!isset($_SESSION['onlineMemberId']) || $_SESSION['onlineMemberId'] == ''){
		if($act != 'login') header("Location: ?act=login");
	}else{
		//-- List all member
		$rsListAllMember = mysql_query("SELECT member_id, member_displayname FROM member");
		while($rowListAllMember = mysql_fetch_array($rsListAllMember)){
			$xtpl_main->assign("listAllMember", $rowListAllMember);
			$xtpl_main->parse("MAIN.listAllMember");
		}
		
		//-- Welcome Block
		$xtpl_main->assign('onlineMemberDisplayName', $_SESSION['onlineMemberDisplayName']);
		$xtpl_main->parse("MAIN.welcome_block");
	}
	
	//--
	$xtpl->parse ( "center" );
	$xtpl_main->assign ( "center_file", $xtpl->text ( "center" ) );
	$xtpl_main->parse ( "MAIN" );
	eval ( "?" . ">" . $xtpl_main->text ( "MAIN" ) );
?>
